/* 
 *  Syntelos XB
 *  Copyright (C) 2006 John Pritchard.
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License as
 *  published by the Free Software Foundation; either version 2 of
 *  the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 *  02111-1307 USA
 */

package syntelos.xb;

/** 
 * 
 * 
 * @author jdp
 */
public class Field 
    extends Base
{
    public final static syntelos.iou.dom.Name NAME = new syntelos.iou.dom.impl.Name(ELEMENT_NODE,"http://www.syntelos.org/xb","xb:field");


    public Field(org.w3c.dom.Document doc, syntelos.iou.dom.Name name){
        super(doc,name);
    }
    public Field(org.w3c.dom.Document doc){
        this(doc,NAME);
    }
    public Field(){
        this(DOC_NIL);
    }

    public boolean isStatic(){
        Access access = this.getAccess(false);
        if (null == access)
            return false;
        else
            return access.isStatic();
    }
    public boolean isPrivate(){
        Access access = this.getAccess(false);
        if (null == access)
            return false;
        else
            return access.isPrivate();
    }
    public boolean isProtected(){
        Access access = this.getAccess(false);
        if (null == access)
            return false;
        else
            return access.isProtected();
    }
    public boolean isPublic(){
        Access access = this.getAccess(false);
        if (null == access)
            return true;
        else
            return access.isPublic();
    }
    public Name getName(){
        return this.getName(true);
    }
    public Name getName(boolean create){
        Name name = (Name)this.getChildByName("name");
        if (null == name && create){
            name = new Name();
            this.appendChild(name);
        }
        return name;
    }
    public final Attributes getAttributesChild(){
        return this.getAttributesChild(true);
    }
    public final Attributes getAttributesChild(boolean create){
        Attributes attributes = (Attributes)this.getChildByName("attributes");
        if (null == attributes && create){
            attributes = new Attributes();
            this.appendChild(attributes);
        }
        return attributes;
    }
    public Access getAccess(){
        return this.getAccess(true);
    }
    public Access getAccess(boolean create){
        Access access = (Access)this.getChildByName("access");
        if (null == access && create){
            access = new Access();
            this.appendChild(access);
        }
        return access;
    }
    public Type.Descriptor getType(){
        return this.getType(true);
    }
    public Type.Descriptor getType(boolean create){
        Type.Descriptor type = (Type.Descriptor)this.getChildByName("type.descriptor");
        if (null == type && create){
            type = new Type.Descriptor();
            this.appendChild(type);
        }
        return type;
    }

    public void readCF(IO.Uri src, CF.Reader reader)
        throws java.io.IOException
    {
        this.getAccess().readCF(src,reader);
        this.getName().readCF(src,reader);
        this.getType().readCF(src,reader);
        this.getAttributesChild().readCF(src,reader);
    }
    public void writeCF(IO.Uri dst, CF.Writer writer)
        throws java.io.IOException
    {
        this.getAccess().writeCF(dst,writer);
        this.getName().writeCF(dst,writer);
        this.getType().writeCF(dst,writer);
        this.getAttributesChild().writeCF(dst,writer);
    }
}
